package com.example.teesystem.mapper;

import com.example.teesystem.entity.AdvancedTraining;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teesystem.entity.vo.advancedTrain.AdTrainRes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 28131
* @description 针对表【t_advanced_training】的数据库操作Mapper
* @createDate 2022-03-31 08:09:45
* @Entity com.example.teesystem.entity.AdvancedTraining
*/
@Mapper
public interface AdvancedTrainingMapper extends BaseMapper<AdvancedTraining> {
    @Select("select course_id from t_advanced_training where id = #{id} and is_delete = 0")
    int getCourseId(int id);

    @Update("update t_advanced_training set message = #{message},is_open = #{isOpen} where id = #{id}")
    void updateMessage(String message, int id, Integer isOpen);

    @Select("select * from t_advanced_training where is_delete = 0 and course_id = #{courseId} and chapter_id = #{chapterId} and pre_advanced_training = 0")
    AdvancedTraining getAdvancedTrainingFirstNode(int courseId,int chapterId);

    @Select("select * from t_advanced_training where is_delete = 0 and course_id = #{courseId} and chapter_id = #{chapterId} and pre_advanced_training = #{preId}")
    AdvancedTraining getAdvancedTrainingMiddleNode(int courseId,int chapterId,int preId);

    @Select("select * from t_advanced_training where id = #{id} and is_delete = 0")
    AdvancedTraining getAdvancedTrainingNodeById(int id);

    @Update("update t_advanced_training set is_delete = 1 where id = #{id}")
    void deleteAdvancedTraining(int id);

    @Select("select * from t_advanced_training where is_delete = 0 and course_id = #{courseId} and chapter_id = #{chapterId} and pre_advanced_training = 0")
    AdTrainRes getAdvancedTrainingFirstNodeAdTrain(int courseId, int chapterId);

    @Select("select * from t_advanced_training where is_delete = 0 and course_id = #{courseId} and chapter_id = #{chapterId} and pre_advanced_training = #{preId}")
    AdTrainRes getAdvancedTrainingMiddleNodeAdTrain(int courseId,int chapterId,int preId);

    @Select("select * from t_advanced_training where is_delete = 0 and course_id = #{courseId}")
    List<AdvancedTraining> getAdvancedTrainingByCourseId(int courseId);

    @Select("select * from t_advanced_training where id = #{id}")
    AdvancedTraining getById(int id);

    @Select("select count(*) from t_advanced_training where course_id = #{courseId} and is_delete = 0")
    Integer getAllNum(int courseId);
}
